<template>
  <div class="toolbar-wrapper">
    <img class="logo" src="@media/common/logo@2x.png">
    <div class="right-bar">
      <div v-if="isShowMenus" class="menus">
        <a class="bar-item" v-for="(nav, i) of navs" :key="nav.path" @click="handleFeature(nav)">
          <span class="route-item" :class="{ active: i == 0 }">{{ nav.name }}</span>
        </a>
      </div>
      <div v-else class="user-info">
        <button class="history-button" v-if="isExpoModule" @click="handleShowShare">{{"分享展会"}}</button>
        <button class="history-button" v-if="isExpoModule && !isShareState" @click="handleShowOperation">{{"展会记录"}}</button>
        <div v-if="!isShareState">
          <div class="user-info-box" @click="isShowMenuList = !isShowMenuList">
            <img class="user-avatar" src="@media/common/icon-avatar.png">
            <span class="user-name">{{userName}}</span>
            <img class="arrow" src="@media/common/icon-drop-arrow@2x.png">
          </div>
          <div class="user-menu-list" v-if="isShowMenuList">
            <div v-for="(menu) of menus" :key="menu.path" class="menu-row" @click="menu.action">
              <img :src="menu.img">
              <span>{{menu.name}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <ResetPasswordDialog></ResetPasswordDialog>
  </div>
</template>

<script>
import ResetPasswordDialog from "@/component/dialog/ResetPasswordDialog";

export default {
  data () {
    return {
      navs: [
        {
          name: '首页',
          path: '/'
        },
        {
          name: '关于我们',
          path: '/about'
        },
        {
          name: '产品信息',
          path: '/information'
        },
        {
          name: '技术支持',
          path: '/support'
        },
        {
          name: '联系我们',
          path: '/contact'
        }
      ],
      isShowMenuList: false,
      isShare: false,
      menus: [
        {
          name: '账户管理',
          path: '/',
          img: require('@media/common/icon-setting@2x.png'),
          action: ()=>{
            this.handleResetPassword()
          },
        },
        {
          name: '退出登录',
          path: '/',
          img: require('@media/common/icon-logout@2x.png'),
          action: ()=>{
            this.handleLogout()
          },
        },
      ]
    };
  },
  methods: {
    handleFeature(nav) {
      if (nav == this.navs[0]) {
        this.$router.push({name: 'home'})
        return
      }
      this.$message('更多内容正在建设，敬请期待！');
    },
    handleResetPassword() {
      this.$store.commit('dialog/RESET_PASSWORD_OPEN', true)
    },
    handleShowOperation() {
      this.$store.commit('dialog/MODULE_OPERATION_RECORD_OPEN', true)
    },
    handleLogout() {
      this.$store.commit('user/LOGOUT')
      this.$router.push({name: 'login'})
      this.$message({
        message: '您已退出云平台系统',
        type: 'success'
      });
    },
    handleShowShare() {
      this.$store.commit('dialog/SHARE_EXPO_OPEN', true)
    }
  },
  computed: {
    isShowMenus() {
      return !this.isLogin && !this.isExpoModule
    },
    userName() {
      return this.$store.getters["user/userName"]
    },
    isExpoModule() {
      return this.$route.name == "expomodule" || this.$route.name == "firstExpomodule"
    },
    isShareState() {
      return this.isShare && this.isExpoModule
    },
    isLogin() {
      return this.$store.getters["user/token"]
    }
  },
  components: {
    ResetPasswordDialog
  },
  created () {
  },
  watch: {
    $route(to, from) {
      if (to == from) {
        return
      }
      this.isShare = this.$route.query.isShare == "1"
      if (!this.isShowMenuList) {
        return
      }
      this.isShowMenuList = false
    }
  }
}
</script>

<style scoped lang="scss">
@import "@/style/scss/component/toolbar.scss"
</style>

